package com.finley.flowabledemo.plc;

import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcpServer;
import com.github.xingshuangs.iot.utils.HexUtil;

import java.util.concurrent.TimeUnit;

public class Demo {

    public static void main(String[] args) throws InterruptedException {

        ModbusTcp modbusTcp = new ModbusTcp("192.168.2.36");
        // optional
        modbusTcp.setComCallback((tag, bytes) -> System.out.printf("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes)));

         modbusTcp.writeInt16(2, (short) 2);
        System.out.println("地址位100,写入的值为:" + 2 );
        TimeUnit.SECONDS.sleep(3);
        short data = modbusTcp.readInt16(2);
        System.out.println("地址位100,的值为:" + data );

        modbusTcp.close();
    }
}
